package mn.slide.laborberlin.adaptor;

import java.util.List;

import mn.slide.laborberlin.main.AnsprechparterDetialActivity;
import mn.slide.laborberlin.main.R;
import mn.slide.laborberlin.model.PListInnerModel;
import mn.slide.laborberlin.tabgroup.GroupStarter;
import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AnspachSubAdapter extends ArrayAdapter<PListInnerModel>
{
	private final List<PListInnerModel>	list;
	private final Activity				context;
	private LayoutInflater				inflate;

	public AnspachSubAdapter( Activity context , List<PListInnerModel> list )
	{
		super(context , R.layout.list_item_middle , list);
		this.list = list;
		this.context = context;
		inflate = context.getLayoutInflater();
	}

	@Override
	public View getView( int position , View convertView , ViewGroup parent )
	{
		View rowView = convertView;
		final ViewHolder child;
		final PListInnerModel model = list.get(position);
		if (rowView == null)
		{
			rowView = inflate.inflate(R.layout.list_item_middle, null, true);
			child = new ViewHolder();
			child.title = (TextView) rowView.findViewById(R.id.title);
			child.subTitle = (TextView) rowView.findViewById(R.id.subtitle);
			child.arrow = (ImageView) rowView.findViewById(R.id.chevron);
			rowView.setTag(child);
		}
		else
		{
			child = (ViewHolder) rowView.getTag();
		}
		rowView.setOnClickListener(new View.OnClickListener()
		{

			@Override
			public void onClick( View v )
			{
				Intent intent = new Intent(context, AnsprechparterDetialActivity.class);
				intent.putExtra("model", model.getChild());
				GroupStarter.getInstance().startActivity(context, intent);
			}
		});
		child.title.setText(model.getValue());

		child.arrow.setVisibility(View.VISIBLE);
		child.subTitle.setVisibility(View.GONE);

		return rowView;
	}

	static class ViewHolder
	{
		protected TextView	title;
		protected TextView	subTitle;

		protected ImageView	arrow;
	}
}
